package com.qiantu.phone.ui.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.gyf.immersionbar.ImmersionBar;
import com.hjq.http.listener.HttpCallback;
import com.hjq.umeng.UmengClient;
import com.qiantu.api.entity.SmsBean;
import com.qiantu.api.http.HttpBaseData;
import com.qiantu.api.http.LLHttpManager;
import com.qiantu.api.http.model.HttpData;
import com.qiantu.phone.BuildConfig;
import com.qiantu.phone.R;
import com.qiantu.phone.aop.Log;
import com.qiantu.phone.aop.SingleClick;
import com.qiantu.phone.app.AppActivity;
import com.qiantu.phone.app.AppApplication;
import com.qiantu.phone.signalr.SignalRManager;
import com.qiantu.phone.ui.dialog.ConfirmHintDialog;
import com.qiantu.phone.ui.dialog.PermissionsConfirmDialog;
import com.qiantu.phone.utils.Constants;
import com.qiantu.phone.utils.SPUtils;
import com.qiantu.phone.utils.StringUtil;
import com.qiantu.phone.widget.EditTextLayout;
import com.qiantu.phone.widget.viewmodel.PasswordLoginPresenter;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

public class PrivateCloudActivity  extends AppActivity {
    private LinearLayout netLayout;
    private LinearLayout localLayout;
    private ImageView netCheck;
    private ImageView localCheck;
    private EditTextLayout apiEditText;
    private EditTextLayout wsEditText;
    private boolean isNetService;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_private_cloud;
    }

    @Override
    protected void initView() {
        getTitleBar().setRightTitle(R.string.save);
        netLayout = findViewById(R.id.net_serivce);
        localLayout = findViewById(R.id.local_service);
        netCheck = findViewById(R.id.net_check);
        localCheck = findViewById(R.id.local_check);
        apiEditText = findViewById(R.id.edit_api);
        wsEditText = findViewById(R.id.edit_ws);
        setOnClickListener(R.id.net_serivce, R.id.local_service);
    }

    @Override
    protected void initData() {
        if(HttpBaseData.getInstance().getLocalServiceUrl() == null){
            isNetService = true;
            netCheck.setSelected(isNetService);
            localCheck.setSelected(!isNetService);
            apiEditText.getEditText().setText("");
            wsEditText.getEditText().setText("");
        }else{
            isNetService = !HttpBaseData.getInstance().isLocalService;
            netCheck.setSelected(isNetService);
            localCheck.setSelected(!isNetService);
            apiEditText.getEditText().setText(HttpBaseData.getInstance().getLocalServiceUrl());
            wsEditText.getEditText().setText(HttpBaseData.getInstance().getLocalServiceWs());
        }
    }

    @Override
    public void onRightClick(View view) {
        HttpBaseData.getInstance().setLocalService(!isNetService);
        HttpBaseData.getInstance().setLocalServiceUrl(apiEditText.getEditText().getText().toString());
        HttpBaseData.getInstance().setLocalServiceWs(wsEditText.getEditText().getText().toString());
        SPUtils.getInstance().put("is_net_service",!isNetService);
        SPUtils.getInstance().put("local_api_url",apiEditText.getEditText().getText().toString());
        SPUtils.getInstance().put("local_ws_url",wsEditText.getEditText().getText().toString());
        finish();

    }

    @SingleClick
    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.net_serivce:
                isNetService = true;
                netCheck.setSelected(true);
                localCheck.setSelected(false);
                break;
            case R.id.local_service:
                isNetService = false;
                netCheck.setSelected(false);
                localCheck.setSelected(true);
                break;
        }
    }
}
